/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package boundary;

import control.ForecastEngine;
import entity.Event;
import entity.User;
import java.util.Date;
import javax.ejb.EJB;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import static org.hamcrest.CoreMatchers.is;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.runner.RunWith;

/**
 *
 * @author Roberto Mussini
 */
@RunWith(Arquillian.class)
public class EventManagerIT {
    

    @EJB
    UserManager cut;
    
    @EJB
    EventManager ef;
      
    
    @PersistenceContext
    EntityManager em;
    


    @Deployment
    public static WebArchive createArchiveAndDeploy() {
        return ShrinkWrap.create(WebArchive.class)
                .addClass(UserManager.class)
                .addClass(EventManager.class)
                .addPackage(User.class.getPackage())
                .addPackage(Event.class.getPackage())
                .addAsResource("test-persistence.xml", "META-INF/persistence.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
    }
   
    @Test
    public void UserManagerShouldBeInjected() {
        assertNotNull(cut);
    }
    
    @Test
    public void EventFacadeShouldBeInjected() {
        assertNotNull(ef);
    }
    
    @Test
    public void EntityManagerShouldBeInjected() {
        assertNotNull(em);
    }

    
    @Test
    public void forecastMustbeCorrect() {
        Event event = new Event();
        event.setPlace("milano");
        Date d = new Date();
        event.setDate(d);
        event.setid(0);
        ForecastEngine fe = new ForecastEngine();
        fe.weather(event);
        ef.em.persist(event);
        Event foundEvent = ef.em.find(Event.class,event.getId());
        assertNotNull(foundEvent);
        assertThat(foundEvent.getPlace(),is(event.getPlace()));
        assertThat(foundEvent.getForecast(),is(event.getForecast()));
    }

    
}
